package com.boot.security.server.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.boot.security.server.model.AppFamMembe;
import com.boot.security.server.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.boot.security.server.page.table.PageTableRequest;
import com.boot.security.server.page.table.PageTableHandler;
import com.boot.security.server.page.table.PageTableResponse;
import com.boot.security.server.page.table.PageTableHandler.CountHandler;
import com.boot.security.server.page.table.PageTableHandler.ListHandler;
import com.boot.security.server.dao.AppTradePaynoDao;
import com.boot.security.server.model.AppTradePayno;

import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("/appTradePaynos")
public class AppTradePaynoController {

    @Autowired
    private AppTradePaynoDao appTradePaynoDao;

    @PostMapping
    @ApiOperation(value = "保存")
    public AppTradePayno save(@RequestBody AppTradePayno appTradePayno) {
        appTradePaynoDao.save(appTradePayno);

        return appTradePayno;
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "根据id获取")
    public AppTradePayno get(@PathVariable Long id) {
        return appTradePaynoDao.getById(id);
    }

    @PutMapping
    @ApiOperation(value = "修改")
    public AppTradePayno update(@RequestBody AppTradePayno appTradePayno) {
        appTradePaynoDao.update(appTradePayno);

        return appTradePayno;
    }

    @GetMapping
    @ApiOperation(value = "列表")
    public PageTableResponse list(PageTableRequest request) {
        return new PageTableHandler(new CountHandler() {

            @Override
            public int count(PageTableRequest request) {
                return appTradePaynoDao.count(request.getParams());
            }
        }, new ListHandler() {

            @Override
            public List<AppTradePayno> list(PageTableRequest request) {
                return appTradePaynoDao.list(request.getParams(), request.getOffset(), request.getLimit());
            }
        }).handle(request);
    }

    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除")
    public void delete(@PathVariable Long id) {
        appTradePaynoDao.delete(id);
    }

    @PostMapping("/find")
    public R findinfo(@RequestBody AppTradePayno appTradePayno){

        Map<String,Object> map = new HashMap<String,Object  >();
        //    map=entityToMap(appAccount);
      //  return new R<>(appTradePaynoDao.getfamlist(appFamMembe.getOpenId(),appFamMembe.getCardno(),appFamMembe.getIdCard(),appFamMembe.getCardtype(),appFamMembe.getPhoneNo()));
        //    return new R<>(  bxbFbqksDao.getById(bxbFbqks.getId()));
        return new R<>();
    }

}
